﻿using System;

namespace TowerCraneMonitorClient.NetClient
{
    public class UnixTimeStamp
    {
        public static readonly DateTime BaseTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
        readonly DateTime time;

        public UnixTimeStamp(DateTime dateTime)
        {
            time = dateTime;
        }

        public UnixTimeStamp(long stamp)
        {
            time = BaseTime.AddSeconds(stamp);
        }

        public long ToLong() => (long)(time.ToUniversalTime() - BaseTime).TotalSeconds;

        public DateTime ToDateTime() => time.ToLocalTime();

        public static UnixTimeStamp Now => new UnixTimeStamp(DateTime.Now);

    }
}
